<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <span>全选:</span>
      <label>
        <input type="checkbox" v-model="selectAll" />
        反选
      </label>
      <ul>
        <li v-for="(item, index) in arr" :key="index">
          <input type="checkbox" v-model="item.c" />
          <span>{{item.name}}</span>
        </li>
      </ul>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          arr: [
            {
              name: '猪八戒',
              c: true
            },
            {
              name: '孙悟空',
              c: true
            },
            {
              name: '唐僧',
              c: true
            },
            {
              name: '白龙马',
              c: true
            }
          ]
        },
        computed: {
          selectAll: {
            get () {
              //   数组的方法拿到boolean值
              //   includes
              //   every:所有项都满足条件  boolean=数组.every(item=>{return 条件 })
              //   some:只要有一个项满足条件
              return this.arr.every(item => item.c === true)
            },
            set (value) {
              console.log(value)
              this.arr.forEach(item => {
                item.c = value
              })
            }
          }
        }
      })
    </script>
  </body>
</html>
